#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
struct Edge {
    int x, y;
} E[5] = {
        {1, 2},
        {1, 3},
        {1, 4},
        {3, 4},
        {4, 5}

};
int Vertex[5] = {1, 2, 3, 4, 5};
int n = 5, m = 5;
int book[6];

void bfs(int x) {
    queue<int> Q;
    Q.push(x);
    book[x] = 1;
    while (!Q.empty()) {
        x = Q.front();
        for (auto e:E) {
            if (e.x == x) {
                if (book[e.y])continue;
                Q.push(e.y);
                book[e.y] = 1;
            }

        }
        cout << x << " ";
        Q.pop();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    bfs(1);


    return 0;
}
